package com.java2007.controller.front;

import com.java2007.controller.BaseServlet;
import com.java2007.factory.BeanFactory;
import com.java2007.service.OrderService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 支付控制层
 */
@WebServlet("/pay")
public class PayController extends BaseServlet {
    private OrderService orderService= (OrderService) BeanFactory.getBean("com.java2007.service.impl.OrderServiceImpl");
    /**
     * 结账
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public String payMoney(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String tableIdStr = (String) request.getSession().getAttribute("tableId");
        Integer tableId = Integer.parseInt(tableIdStr);

        //修改支付状态
        int i = orderService.changeStatus(tableId,1);

        //清除所有的session
        HttpSession session = request.getSession();
        session.removeAttribute("table_id");
        session.removeAttribute("orderId");
        session.removeAttribute("order_detail_list");
        session.removeAttribute("order_total_price");
        session.removeAttribute("admin");
        return "redirect:/index.jsp";
    }
}
